package com.itheima.common.result;


import lombok.Data;

import java.io.Serializable;

/**
 * @author zhengbinghua
 * @since 2022/10/13 16:11
 */
@Data
public class JsonResult implements Serializable {
    private Integer code; // 1-成功  0-失败
    private String msg;
    private Object data;

    public JsonResult() {
    }

    public JsonResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static JsonResult success(Object data){
        return new JsonResult(Code.SUCCESS, "操作成功", data);
    }

    public static JsonResult fail(String msg){
        return new JsonResult(Code.FAIL, msg, null);
    }

    public static JsonResult error(String msg){
        return new JsonResult(Code.ERROR, msg, null);
    }
}